var app = getApp();
// 获得画布的绘图上下文
const ctx = wx.createCanvasContext("myCanvas");
// 画布缩放的大小
const canvasScale = 0.88,
    iconSize = 20; //图、字小图画的大小
let loadingFlag = false;
let nowbackground = 0; //标识现在正在使用哪个背景图
Page({
    /**
     * 页面的初始数据
     */
    data: {
        // 控制图字转换的样式
        nid: "ptu",
        zid: "zi",
        // 画布默认绘制的背景图
        avatar: "https://api.jinjin.work:6001/images/empty-tuan.png",
        imgPath: "https://api.jinjin.work:6001/images/empty-tuan.png",
        localCacheBackgroundArr: [{
                src: 'https://api.jinjin.work:6001/images/empty-tuan.png',
                path: '',
                desHeight: 300,
                desWidth: 300
            },
            {
                src: 'https://api.jinjin.work:6001/images/empty-zhe.png',
                path: '',
                desHeight: 300,
                desWidth: 300
            }
        ], //本地缓存画布背景图数组，索引0为empty-tuan，索引1为empty-zhe

        avatarTmp: null,
        // 存储图片的本地数组
        iconTmp: [],
        // 存储选中的图，字的相关信息的数组
        targetIcon: [],
        // this.data.current表示ti数组最后一项的index值
        current: 0,
        // cap_index表示当前选中的图的标识
        cap_index: 0,
        // seq_index表示图片的图层序列
        seq_index: 0,
        startX: 0,
        startY: 0,
        desWidth: 300,
        desHeight: 300,

        showAd: false,
        showCapAd: false,
        delFlag:true,

        // 默认显示所有图
        base: [
            // "https://s3.bmp.ovh/imgs/2021/11/e925cbe91050010e.png",
            // "https://s3.bmp.ovh/imgs/2021/11/91f2a8769447ab7c.png",
            // "https://s3.bmp.ovh/imgs/2021/11/651275ea465321db.png",
            // "https://s3.bmp.ovh/imgs/2021/11/5928886ceebc22f5.png",
            // "https://s3.bmp.ovh/imgs/2021/11/a479d81bb38f8b23.png",
            // "https://s3.bmp.ovh/imgs/2021/11/3485348add8f4e37.png",

            "https://api.jinjin.work:6001/images/p1.png",
            "https://api.jinjin.work:6001/images/p2.png",
            "https://api.jinjin.work:6001/images/p3.png",
            "https://api.jinjin.work:6001/images/p4.png",
            "https://api.jinjin.work:6001/images/p5.png",
            "https://api.jinjin.work:6001/images/p6.png",

            // "https://api.hiehie.top:6001/images/p1.png",
            // "https://api.hiehie.top:6001/images/p2.png",
            // "https://api.hiehie.top:6001/images/p3.png",
            // "https://api.hiehie.top:6001/images/p4.png",
            // "https://api.hiehie.top:6001/images/p5.png",
            // "https://api.hiehie.top:6001/images/p6.png",
        ],
        // 所有图资源
        baseA: [
            // "https://s3.bmp.ovh/imgs/2021/11/e925cbe91050010e.png",
            // "https://s3.bmp.ovh/imgs/2021/11/91f2a8769447ab7c.png",
            // "https://s3.bmp.ovh/imgs/2021/11/651275ea465321db.png",
            // "https://s3.bmp.ovh/imgs/2021/11/5928886ceebc22f5.png",
            // "https://s3.bmp.ovh/imgs/2021/11/a479d81bb38f8b23.png",
            // "https://s3.bmp.ovh/imgs/2021/11/3485348add8f4e37.png",

            "https://api.jinjin.work:6001/images/p1.png",
            "https://api.jinjin.work:6001/images/p2.png",
            "https://api.jinjin.work:6001/images/p3.png",
            "https://api.jinjin.work:6001/images/p4.png",
            "https://api.jinjin.work:6001/images/p5.png",
            "https://api.jinjin.work:6001/images/p6.png",

            // "https://api.hiehie.top:6001/images/p1.png",
            // "https://api.hiehie.top:6001/images/p2.png",
            // "https://api.hiehie.top:6001/images/p3.png",
            // "https://api.hiehie.top:6001/images/p4.png",
            // "https://api.hiehie.top:6001/images/p5.png",
            // "https://api.hiehie.top:6001/images/p6.png",
        ],
        // 所有字资源
        baseB: [
            // "https://s3.bmp.ovh/imgs/2021/11/2d632bfb5db68926.png",
            // "https://s3.bmp.ovh/imgs/2021/11/5008952c0c3a93aa.png",
            // "https://s3.bmp.ovh/imgs/2021/11/fc07b8eaa1feb1ed.png",
            // "https://s3.bmp.ovh/imgs/2021/11/e584fb4dfcb3b725.png",
            // "https://s3.bmp.ovh/imgs/2021/12/4c8273ffa60640a8.png",
            // "https://s3.bmp.ovh/imgs/2021/12/1fe6fd16bb7392f0.png",
            "https://api.jinjin.work:6001/images/c1.png",
            "https://api.jinjin.work:6001/images/c2.png",
            "https://api.jinjin.work:6001/images/c3.png",
            "https://api.jinjin.work:6001/images/c4.png",
            "https://api.jinjin.work:6001/images/c5.png",
            "https://api.jinjin.work:6001/images/c6.png",
            // "https://api.hiehie.top:6001/images/c1.png",
            // "https://api.hiehie.top:6001/images/c2.png",
            // "https://api.hiehie.top:6001/images/c3.png",
            // "https://api.hiehie.top:6001/images/c4.png",
            // "https://api.hiehie.top:6001/images/c5.png",
            // "https://api.hiehie.top:6001/images/c6.png",
        ],
    },
    bindAnimation() {
        var this_ = this;
        var animation = wx.createAnimation({
            duration: 14000,
            timingFunction: 'linear',
            transformOrigin: "100% 0 0"
        })
        animation.translateX('-100%').step();
        this.setData({
            animation: animation.export(),
        })
        //设置循环动画
        this.animation = animation;
        setInterval(function () {
            //第二个动画 文字位置初始化
            this.Animation2();
            //延迟播放滚动动画（效果会更好点）
            setTimeout(function () {
                this.animation.translateX('-100%').step();
                this.setData({
                    animation: animation.export(),
                })
            }.bind(this), 200);
        }.bind(this), 14000);

    },
    /**
     * 第二个动画 文字位置初始化
     */
    Animation2() {
        var this_ = this;
        var animation2 = wx.createAnimation({
            duration: 0,
            timingFunction: 'linear',
            transformOrigin: "100% 0 0"
        })
        animation2.translateX('100%').step();
        this_.setData({
            animation: animation2.export(),
        })
    },

    // 页面加载时获取屏幕的信息从而确定画布的位置以及大小
    onLoad: function (options) {
        wx.getSystemInfo({
            success: (res) => {
                this.setData({
                    sys: res,
                    height: res.windowWidth * canvasScale,
                });
            },
        });
    },

    // 页面显示
    onShow: function () {
        // 获取所有的图片
        this.getIcons();
        // 绘制背景
        if (this.data.avatar.indexOf("empty-tuan.png") > 0) {
            this.getAvatar();
        }
        // if (this.data.avatar.indexOf("a9d8c39201a051da.png") > 0) {
        //     this.getAvatar();
        // }
    },
    // 页面渲染的时候绘制背景，并且显示所有图片
    onReady: function () {
        this.drawAvatar(1);
        this.bindAnimation();
        if (this.data.avatar.indexOf("empty-tuan.png") > 0) {
            this.getAvatar()
        };
        // if (this.data.avatar.indexOf("a9d8c39201a051da.png") > 0) this.getAvatar();
    },

    // 图按钮
    changeP: function () {
        // if (app.globalData.flag == true) {
        //     this.setData({
        //         nid: "ptu",
        //         zid: "zi"
        //     });
        //     // app.globalData.flag = false;
        // }
        // -----------
        this.setData({
            nid: "ptu",
            zid: "zi"
        });
        app.globalData.flag = true;
        // -----------
        // if (app.globalData.flag1 == false) {
        //     this.setData({
        //         nid: "ptu",
        //         zid: "zi",
        //     });
        //     app.globalData.flag = false;
        // }
        this.setData({
            base: this.data.baseA,
        });
        this.getIcons();
    },

    // 字按钮
    changeC: function () {
        // if (app.globalData.flag1 == true) {
        //     this.setData({
        //         zid: "czi",
        //         nid: "tu",
        //     });
        //     app.globalData.flag1 = false;
        // }

        // if (app.globalData.flag == false) {
        //     this.setData({
        //         zid: "czi",
        //         nid: "tu",
        //     });
        //     app.globalData.flag1 = false;
        // }
        // -----------
        this.setData({
            zid: "czi",
            nid: "tu",
        });
        app.globalData.flag = false;
        // -----------
        this.setData({
            base: this.data.baseB,
        });
        this.getIcons();
    },

    // 涂鸦绑定事件
    changeT: function () {
        // 传入当前页面扇子的路径
        wx.navigateTo({
            url: "/pages/paint/paint?id=" + this.data.avatar + "&title=" + this.data.localCacheBackgroundArr[nowbackground].src,
        });
    },

    // 图片被选中时触发的事件
    tap: function (e) {
        // console.log("e:",e)
        var ti = this.data.targetIcon,
            cap = e.currentTarget.id.substring(3);
        // cap表示当前选中的图片的唯一id标识
        // 每点一个就会向ti中压入一个对应图片的位置、大小以及旋转角度
        ti.push({
            cap_index: cap,
            px: Math.floor(Math.random() * 181) + 20,
            py: Math.floor(Math.random() * 181) + 20,
            degree: 0,
            size: 80,
            seq_index: ti.length,
            isPicOrWordflag: app.globalData.flag
        });
        this.setData({
            current: ti.length - 1,
            targetIcon: ti,
            cap_index: cap,
        });
        // this.data.current表示ti数组最后一项的index值
        // cap_index表示当前选中的图的标识
        // 将图片绘制到画布
        this.drawCap();
    },

    sliderchange: function (e) {
        this.data[e.currentTarget.id] = e.detail.value;
        this.drawCap();
    },

    // 选取自定义背景
    choose: function () {
        wx.chooseImage({
            count: 1,
            sizeType: ["original", "compressed"],
            sourceType: ["album"],
            success: (res) => {
                wx.getImageInfo({
                    src: res.tempFilePaths[0],
                    success: (res) => {
                        this.data.desHeight = res.height;
                        this.data.desWidth = res.width;
                    },
                });
                this.setData({
                    avatar: res.tempFilePaths[0],
                    imgPath: "",
                });
                this.drawCap();
            },
        });
    },

    // 对背景进行绘制并保存
    getAvatar: function () {
        var avatar = this.data.avatar,
            that = this;
        console.log(avatar)
        console.log(nowbackground)
        // let pro = new Promise(function (resolve, reject) {
        let temp = this.data.localCacheBackgroundArr[nowbackground].path;
        //------------------

        if (temp == "") { //如果temp数组为空即本地没有缓存这个图片，那么发起请求,并将返回的地址存入本地
            wx.getImageInfo({
                src: this.data.localCacheBackgroundArr[nowbackground].src,
                success: (res) => {
                    that.data.desHeight = res.height;
                    that.data.desWidth = res.width;
                    let templist = this.data.localCacheBackgroundArr;
                    templist[nowbackground].path = res.path;
                    templist[nowbackground].desHeight = res.height;
                    templist[nowbackground].desWidth = res.width;
                    that.setData({

                        localCacheBackgroundArr: templist
                    });
                    that.getAvatar();
                    // ctx.draw();
                    // that.getIcons();
                    loadingFlag = false;
                },
                fail: (e) => {
                    loadingFlag = false;
                },
            });
        } else { //本地有这个图片的缓存，那就使用本地缓存的路径
            this.setData({
                avatar: temp,
            })
            that.drawAvatar();
            ctx.draw();
            that.getIcons();
            loadingFlag = false;
        }

    },

    // 显示所有图片资源
    getIcons: function () {
        // 获取所有的图片资源
        var base = this.data.base;
        this.setData({
            icons: base,
            showCapAd: this.data.showCapAd,
        });
        // 绘制图片
        this.drawCap();
    },

    // 获取绘制图片的大小
    getCapWidth(size) {
        return size;
    },

    // 获取样式的旋转角度和位置
    getRotatePosition(x, y, rx0, ry0, degree) {
        var x0 = (x - rx0) * Math.cos(degree) - (y - ry0) * Math.sin(degree) + rx0,
            y0 = (x - rx0) * Math.sin(degree) + (y - ry0) * Math.cos(degree) + ry0;
        return [Number(x0), Number(y0)];
    },

    // 绘制图片
    drawCap: function (save) {
        // console.log("app.globalData.flag:",app.globalData.flag)
        // console.log("app.globalData.flag1:",app.globalData.flag1)
        // console.log('---------------------------------------------------------')
        // console.log("this.data:",this.data)
        // 存储图片的本地数组
        var itmp = this.data.iconTmp,
            that = this,
            // 当图片被绘制上去时将图标压入targetIcon数组中
            t_icon = this.data.targetIcon;

        // 获取画布尺寸
        var hei = this.data.height;
        ctx.clearRect(0, 0, hei, hei);

        // 绘制图片的同时绘制背景
        this.drawAvatar();
        for (var ti in t_icon) {
            // console.log(ti)
            //遍历要绘制的图片
            var obj = t_icon[ti];
            // console.log(obj)
            if (!obj) return;
            var px = obj.px,
                py = obj.py,
                index = obj.cap_index,
                seq_index = obj.seq_index,
                size = obj.size,
                degree = obj.degree,
                isPicOrWordflag = obj.isPicOrWordflag; // 标志位，标志这个对象是字例还是图例
            var wid = this.getCapWidth(size); //图片的宽高
            //----------修改的
            // var tmp = this.data.iconTmp[seq_index];
            var tmp = undefined; //默认为没缓存
            for (let l = 0; l < this.data.iconTmp.length; l++) {
                let {
                    cap_index,
                    flag
                } = this.data.iconTmp[l];
                // console.log(cap_index , flag);
                if ((cap_index == index) && (flag == isPicOrWordflag)) { // 判断当前要渲染的图片的index和序列(是图例还是字例)标志与本地缓存的是否相等
                    tmp = this.data.iconTmp[l].path; //若缓存了则改为缓存的路径
                }
            }
            //-----------修改结束
            if (!tmp) {
                // console.log("执行了本地未缓存");
                //图片未缓存，下载后再重新调用
                wx.getImageInfo({
                    src: this.data.icons[index],
                    success: (res) => {
                        // this.data.iconTmp[ti] = {//------此处被修改，原来是直接=res.path
                        //     cap_index:index,
                        //     path:res.path,
                        //     flag:app.globalData.flag // 这个标志用于判断是图的还是字的，true为图，false为字
                        // };
                        // ---------修改的----------
                        let pushflag = true; //决定是否要将这个图片缓存进本地缓存数组
                        this.data.iconTmp.push({ //------此处被修改，原来是直接=res.path
                            cap_index: index,
                            path: res.path,
                            flag: app.globalData.flag // 这个标志用于判断是图的还是字的，true为图，false为字
                        })
                        // ------------------------
                        this.drawCap();
                    },
                });
                return;
            } else {
                // console.log("执行了本地已经缓存");
                // console.log(tmp)
                //图片已缓存
                degree = (degree * Math.PI) / 180;
                var ox = px + wid / 2,
                    oy = py + wid / 2;
                ctx.translate(ox, oy);
                ctx.rotate(degree);
                ctx.translate(-wid / 2, -wid / 2);
                ctx.drawImage(tmp, 0, 0, wid, wid);
                //为当前选择对象 绘制虚线框
                if (ti == this.data.current && !save) {
                    ctx.setStrokeStyle("#FF6A6A");
                    ctx.setLineWidth(3);
                    ctx.setLineDash([10, 7], 8);
                    ctx.rect(0, 0, wid, wid);
                    ctx.stroke();
                    ctx.drawImage(
                        "/imgs/delete.png",
                        -iconSize / 2,
                        -iconSize / 2,
                        iconSize,
                        iconSize
                    );
                    ctx.drawImage(
                        "/imgs/rotate.png",
                        wid - iconSize / 2,
                        wid - iconSize / 2,
                        iconSize,
                        iconSize
                    );
                }
                ctx.rotate(-degree);
                //计算当前原点绕图标中心旋转后的坐标
                var rx0 = wid / 2,
                    ry0 = wid / 2,
                    x = 0,
                    y = 0,
                    pos = this.getRotatePosition(x, y, rx0, ry0, degree);
                var x0 = pos[0],
                    y0 = pos[1];
                //将原点恢复为 0,0
                ctx.translate(-px - x0, -py - y0);
                obj.ox = ox;
                obj.oy = oy;
                this.data.targetIcon[ti] = obj;
            }
        }
        if (!save) ctx.draw();
        else {
            //保存图片
            const token = wx.getStorageSync("token");
            if (app.globalData.isLogin == false) {
                wx.showModal({
                    title: "未登录",
                    content: "您还没有登录哦，快去登录吧！",
                    confirmText: "去登录",
                    showCancel: false,
                    success: (res) => {
                        if (res.confirm) {
                            wx.switchTab({
                                url: "/pages/myCenter/myCenter",
                            });
                        }
                    },
                });
            } else {
                //保存图片
                ctx.draw(false, () => {
                    wx.canvasToTempFilePath({
                        x: 0,
                        y: 0,
                        width: this.data.height,
                        height: this.data.height,
                        destWidth: 280,
                        destHeight: 300,
                        canvasId: "myCanvas",
                        success(res) {
                            var filePath = res.tempFilePath;
                            console.log(res.tempFilePath);
                            wx.showModal({
                                content: "已保存到我的设计，是否保存到本地相册",
                                confirmText: "是",
                                cancelText: "否",
                                success: (res) => {
                                    if (res.confirm) {
                                        // 图片保存到手机本地相册
                                        wx.saveImageToPhotosAlbum({
                                            filePath: filePath,
                                            success(res) {
                                                wx.showToast({
                                                    title: "保存成功",
                                                });
                                                that.setData({
                                                    showAd: true,
                                                });
                                            },
                                        });
                                    }
                                },
                            });
                            // 图片上传到服务器
                            wx.uploadFile({
                                filePath: res.tempFilePath,
                                name: "img",
                                url: `${app.globalData.url}/design`,
                                header: {
                                    Authorization: token,
                                },
                                success: (res) => {
                                    console.log(res);
                                },
                                fail: (err) => {
                                    console.log(err);
                                },
                            });
                        },
                    });
                });
            }
        }
    },

    // 清除画布后重新绘制背景图片
    drawAvatar: function (draw) {
        var hei = this.data.height;
        // ---------修改开始--------
        // 原来：this.data.imgPath.indexOf("empty-tuan.png") > 0
        if (nowbackground == 0) {
            ctx.drawImage(
                this.data.localCacheBackgroundArr[nowbackground].path,
                55,
                0,
                hei * 0.67,
                hei,
                0,
                0,
                this.data.localCacheBackgroundArr[0].desWidth,
                this.data.localCacheBackgroundArr[0].destHeight
            );
            // 原来：this.data.imgPath.indexOf("empty-zhe.png")
        } else if (nowbackground == 1) {
            ctx.drawImage(
                this.data.avatar,
                6,
                30,
                hei,
                hei / 1.25,
                0,
                0,
                this.data.localCacheBackgroundArr[1].desWidth,
                this.data.localCacheBackgroundArr[1].destHeight
            );
        } else {
            ctx.drawImage(this.data.avatar, 0, 0, hei, hei);
        }
        if (draw) ctx.draw();
    },

    //开始拖拽
    start: function (e) {
        var sx = e.changedTouches[0].x,
            sy = e.changedTouches[0].y,
            t_icon = this.data.targetIcon;
        this.data.current = t_icon.length - 1;
        this.data.startX = sx;
        this.data.startY = sy;
        //防止同时作用于多个图标
        if (this.data.scaleMode) return;
        for (var i = t_icon.length - 1; i >= 0; i--) {
            //倒序读取，因为后添加的会覆盖在之前添加的上面
            var obj = t_icon[i],
                wid = Number(this.getCapWidth(obj.size)),
                px = Number(obj.px),
                py = Number(obj.py),
                degree = (obj.degree * Math.PI) / 180;
            var pos = this.getRotatePosition(0, 0, wid / 2, wid / 2, degree);
            //图标左上角的坐标px,py;右下角的rx,ry
            px += pos[0];
            py += pos[1];
            //console.log(px+' '+py+' '+sx+' '+sy);
            pos = this.getRotatePosition(wid, wid, wid / 2, wid / 2, degree);
            var rx = pos[0],
                ry = pos[1];
            //删除动作
            var off = iconSize / 2; //图标大小的一半
            if (sx >= px - off && sx <= px + off && sy >= py - off && sy <= py + off) {
                this.data.targetIcon.splice(i, 1);
                this.drawCap();
                return;
            }
            //旋转缩放动作
            px = Number(obj.px);
            py = Number(obj.py); //恢复到旋转前的坐标
            if (
                sx >= px + rx - off &&
                sx <= px + rx + off &&
                sy >= py + ry - off &&
                sy <= py + ry + off
            ) {
                this.data.scaleMode = 1; //按住了缩放
                return; //防止同时作用于多个图标
            }
            if (sx >= px && sy >= py && sx <= px + wid && sy <= py + wid) {
                //交换位置，把选中的移到最后面，这样才能让其显示在最上面
                [t_icon[i], t_icon[this.data.current]] = [t_icon[this.data.current], t_icon[i]];
                break;
            }
        }
    },

    // 拖拽过程中
    move: function (e) {
        var nx = e.changedTouches[0].x,
            ny = e.changedTouches[0].y,
            sx = this.data.startX,
            sy = this.data.startY;
        var ti = this.data.targetIcon,
            current = this.data.current;
        if (!this.data.scaleMode) {
            var obj = ti[current];
            if (!obj) return;
            var wid = Number(this.getCapWidth(obj.size)),
                px = Number(obj.px),
                py = Number(obj.py);
            //触摸到图标区域
            if (sx >= px && sy >= py && sx <= px + wid && sy <= py + wid) {
                obj.px += nx - sx;
                obj.py += ny - sy;
            }
            ti[current] = obj;
        } else {
            //缩放模式
            var obj = ti[current],
                wid = this.getCapWidth(obj.size),
                px = obj.px,
                py = obj.py;
            var ox = obj.ox,
                oy = obj.oy; //px+wid/2
            var old = Math.sqrt((sx - ox) * (sx - ox) + (sy - oy) * (sy - oy)),
                now = Math.sqrt((nx - ox) * (nx - ox) + (ny - oy) * (ny - oy));
            //旧半径，要保持旋转中心不变
            var old_size = ti[current].size;
            ti[current].size = now * Math.SQRT2;
            ti[current].px = ox - ti[current].size / 2;
            ti[current].py = oy - ti[current].size / 2;
            var [y, x] = [ny - oy, nx - ox],
            tan_a = (y * 1.0) / x,
                tan_b = 1,
                origin_degree = (Math.atan(tan_a) * 180) / Math.PI,
                rotate_degree = origin_degree - 45;

            //处理一些特殊情况
            if ((y >= 0 && x < 0) || (y < 0 && x < 0)) rotate_degree = 135 + origin_degree;

            // console.log(origin_degree + ' ' + rotate_degree + ' ' + y + ' ' + x)
            ti[current].degree = rotate_degree;
            //  console.log(ox+' now:['+nx+','+ny+'] '+(ny-oy)+' '+(nx-ox)+' '+ti[current].degree)
        }
        this.data.targetIcon = ti;
        this.data.startX = nx;
        this.data.startY = ny;
        this.drawCap();
    },

    // 拖拽结束
    end: function (e) {
        this.data.scaleMode = 0;
        //获取头像
        if (this.data.avatar.indexOf("empty-tuan.png") > 0) this.getAvatar();
        // if (this.data.avatar.indexOf("a9d8c39201a051da.png") > 0) this.getAvatar();
    },

    // 保存图片
    save: function () {
        this.drawCap(1);
    },

    // 左边小三角绑定的事件
    changeTypeLeft: function () {
        // if (app.globalData.left == true) {
        //     this.setData({
        //         avatar: "https://api.hiehie.top:6001/images/empty-zhe.png",
        //         imgPath: "https://api.hiehie.top:6001/images/empty-zhe.png",
        //     });
        //     app.globalData.left = false;
        //     app.globalData.right = true;
        // } else {
        //     this.setData({
        //         avatar: "https://api.jinjin.work:6001/images/empty-tuan.png",
        //         imgPath: "https://api.jinjin.work:6001/images/empty-tuan.png",
        //     });
        //     app.globalData.left = true;
        //     app.globalData.right = false;
        // }
        if (nowbackground == 0 && !loadingFlag) {
            loadingFlag = true;
            nowbackground = 1;
            this.getAvatar();
        } else if (nowbackground == 1 && !loadingFlag) {
            loadingFlag = true;
            nowbackground = 0;
            this.getAvatar();
        }

    },

    // 右边小三角绑定的事件
    changeTypeRight: function () {
        // if (app.globalData.right == true) {
        //     this.setData({
        //         avatar: "https://api.jinjin.work:6001/images/empty-tuan.png",
        //         imgPath: "https://api.jinjin.work:6001/images/empty-tuan.png",
        //     });
        //     app.globalData.right = false;
        //     app.globalData.left = true;
        // } else {
        //     this.setData({
        //         avatar: "https://api.hiehie.top:6001/images/empty-zhe.png",
        //         imgPath: "https://api.hiehie.top:6001/images/empty-zhe.png",
        //     });
        //     app.globalData.right = true;
        //     app.globalData.left = false;
        // }
        if (nowbackground == 0 && !loadingFlag) {
            loadingFlag = true;
            nowbackground = 1;
            this.getAvatar();
        } else if (nowbackground == 1 && !loadingFlag) {
            loadingFlag = true;
            nowbackground = 0;
            this.getAvatar();
        }

    },
    deleteNode:function(e){
        // let query = wx.createSelectorQuery();
        // query.select('.footer').boundingClientRect(function(rect){
        //     console.log(rect)
        // }).exec()
        if(this.data.delFlag==true){
            this.setData({
                delFlag:false
            })
        }
        
    }
});